package com.easylive.web.controller;

import com.easylive.entity.dto.TokenUserInfoDto;
import com.easylive.entity.enums.ResponseCodeEnum;
import com.easylive.entity.enums.VideoStatusEnum;
import com.easylive.entity.po.VideoComment;
import com.easylive.entity.po.VideoInfo;
import com.easylive.entity.po.VideoInfoFilePost;
import com.easylive.entity.po.VideoInfoPost;
import com.easylive.entity.query.VideoCommentQuery;
import com.easylive.entity.query.VideoInfoFilePostQuery;
import com.easylive.entity.query.VideoInfoPostQuery;
import com.easylive.entity.query.VideoInfoQuery;
import com.easylive.entity.request.ucenter.WebUcenterLoadVideoList;
import com.easylive.entity.request.ucenter.WebUcenterPostVideoReqVO;
import com.easylive.entity.vo.PaginationResultVO;
import com.easylive.entity.vo.ResponseVO;
import com.easylive.entity.vo.VideoPostEditInfoVO;
import com.easylive.entity.vo.VideoStatusCountInfoVO;
import com.easylive.exception.BusinessException;
import com.easylive.service.*;
import com.easylive.utils.JsonUtil;
import com.easylive.utils.StringTools;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;
import java.util.List;
import java.util.Objects;

/**
 * @Author: yudaxian
 * @DateTime: 2024/11/8 15:58
 **/
@RestController
@RequestMapping("/ucenter")
public class UcenterInteractionController extends ABaseController {

    /**
     * 发布用的
     */
    @Resource
    private VideoInfoPostService videoInfoPostService;

    @Resource
    private VideoInfoFilePostService videoInfoFilePostService;

    /**
     * 查看用的
     */
    @Resource
    private VideoInfoService videoInfoService;

    @Resource
    private VideoInfoFileService videoInfoFileService;

    @Resource
    private VideoCommentService videoCommentService;

    @PostMapping("/loadAllVideo")
    public ResponseVO loadAllVideo() {

        TokenUserInfoDto tokenUserInfoDto = getTokenUserInfoDto();
        VideoInfoQuery videoInfoQuery = new VideoInfoQuery();
        videoInfoQuery.setUserId(tokenUserInfoDto.getUserId());
        videoInfoQuery.setOrderBy("create_time desc");

        List<VideoInfo> videoInfoList = videoInfoService.findListByParam(videoInfoQuery);

        return getSuccessResponseVO(videoInfoList);
    }

    @PostMapping("/loadComment")
    public ResponseVO loadComment(@Validated Integer pageNo, Integer pageSize, String videoId) {

        TokenUserInfoDto tokenUserInfoDto = getTokenUserInfoDto();
        VideoCommentQuery videoCommentQuery = new VideoCommentQuery();
        videoCommentQuery.setVideoId(videoId);
        videoCommentQuery.setVideoUserId(tokenUserInfoDto.getUserId());
        videoCommentQuery.setOrderBy("comment_id desc");
        videoCommentQuery.setPageNo(pageNo);
        videoCommentQuery.setPageSize(pageSize);
        videoCommentQuery.setQueryVideoInfo(true);

        PaginationResultVO<VideoComment> page = videoCommentService.findListByPage(videoCommentQuery);

        return getSuccessResponseVO(page);
    }
}
